#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
            
def main():
#     global frequence_dict
#     init_common_words()
    
    output_file_name = '/home/ivy/git/Social/Social/resource/like/temp_like.txt'
#     sort_file_name = '/home/ivy/git/Social/Social/resource/like.txt'
    
    current_user = ''
    text = ''
    with open(output_file_name, "a+") as outputfile:
        for i in range(1, 15):
            print i
            input_file_name = '/home/ivy/git/Social/Social/resource/json_tweets/json_tweets_%d.txt' % i
            with open(input_file_name, "r") as inputfile:
                for line in inputfile:
                    obj = json.loads(line)
                    user = obj['users']
                    status = obj['status']
                    if user != current_user:
                        #write into file
                        if current_user != '':
                            outputfile.write('%s\t%s\n' % (current_user,text))
                        current_user = user
                        text = ''
                    
                    text += obj['text'] + ' '
                    if 1 == status:
                        text += obj['quoted_quoted_text']
                    if 2 == status:
                        text += obj['retweeted_text']
                    if 3 == status:
                        text += obj['retweeted_text'] + ' '
                        text += obj['quoted_quoted_text']
            
            outputfile.flush()
    
    outputfile.close()
    
#     sort(output_file_name, sort_file_name)
    
if __name__ == '__main__':
    main() 